package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.PastDealHandler;
import com.cungmua.app.model.request.PastDealRequest;
import com.cungmua.app.model.response.PastDealResponse;
import com.cungmua.app.net.CungMuaAPI;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 6/25/14.
 */
public class PastDealTask extends AuthenticatedTask<PastDealRequest, Void, PastDealResponse> {

    private final PastDealHandler handler;
    private final Context context;

    public PastDealTask(Context context, PastDealHandler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected PastDealResponse doInBackground() throws RetrofitError {
        PastDealRequest request = params[0];
        return CungMuaAPI.getService().getListPastDeal(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(PastDealResponse pastDealResponse) {
        handler.onListPastDeal(pastDealResponse);
    }
}

